<?php echo $this->Form->create('NguoidungNhom', array('type' => 'post', 'action' => 'index')); ?>
<div style="margin-left: 30px;"><?php echo $this->element('message'); ?></div>
<div align="center" class="ajaxLoading">
<?php if(isset( $false )){ ?>
<table width="700" border="0" cellpadding="5">
    <tr>
        <td colspan="5"><div align="center"><span style="font-size: 18px;font-weight: bold;">PHÂN NGƯỜI DÙNG VÀO NHÓM</span></div></td>
    </tr>
    <tr>
        <td width="137">Nhóm quyền</td>
        <td colspan="4">
            <?php
                echo $this->Form->input('nhomid', array(
                            'options' => $arr_Nhom,
                            'label' => false,
                            'style' =>  'width:350px;',
                            'empty' => '---- Chọn nhóm ----',
                            'onchange' => 'load(this.value)'
                        ));
            ?>
        </td>
    </tr>
    <tr>
        <td>Chưa phân quyền</td>
        <td width="77">&nbsp;</td>
        <td width="110">&nbsp;</td>
        <td width="104">Đã phân quyền</td>
        <td width="110">&nbsp;</td>
    </tr>
        <tr>
            <td colspan="2" rowspan="8">
                <select id="leftValues" size="4" MULTIPLE style="height:300px;width:100%;">
                </select>
            </td>
            <td>&nbsp;</td>
            <td colspan="2" rowspan="8">
                <select size="4" id="rightValues"  MULTIPLE style="height:300px;width:100%;">
                </select>
            </td>
        </tr>
        <tr>
            <td>
                <div align="center">
                    <input id="btnRight" type="Button" value=">" style="width:50px" />
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div align="center">
                    <input id="btnLeft" type="Button" value="<" style="width:50px" />
                </div>
            </td>
        </tr>
        <tr>
            <td>&nbsp;</td>
        </tr>
        <tr>
          <td>
            <div align="center">
                <input type="submit" style="width:50px" value="Lưu" />
                <input type="hidden" name="hidden_nguoidung_nhom_id" value="<?php if(isset( $nguoidung_nhom_id )) echo $nguoidung_nhom_id;  ?>" />
            </div>
          </td>
        </tr>
        <tr>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td>&nbsp;</td>
        </tr>
</table>
<?php }else{ ?>

    <table width="700" border="0" cellpadding="5">
        <tr>
            <td colspan="5"><div align="center"><span style="font-size: 18px;font-weight: bold;">PHÂN NGƯỜI DÙNG VÀO NHÓM</span></div></td>
        </tr>
        <tr>
            <td width="137">Nhóm quyền</td>
            <td colspan="4">
                <?php
                    echo $this->Form->input('nhomid', array(
                                'options' => $arr_Nhom,
                                'label' => false,
                                'style' =>  'width:350px;',
                                'empty' => '---- Chọn nhóm ----',
                                'onchange' => 'load(this.value)',
                                'selected' => $nhom_id
                            ));
                ?>
            </td>
        </tr>
        <tr>
            <td>Chưa phân quyền</td>
            <td width="77">&nbsp;</td>
            <td width="110">&nbsp;</td>
            <td width="104">Đã phân quyền</td>
            <td width="110">&nbsp;</td>
        </tr>
        <tr>
            <td colspan="2" rowspan="8">
                <?php
                    echo $this->Form->input('chuaphanquyen', array(
                                'options' => $arr_list_id_Nguoidungchuphanquyen,
                                'label' => false,
                                'style' =>  'height: 300px; width: 100%; padding-left: 3px; padding-top: 3px; padding-bottom: 3px;',
                                'type' => 'select',
                                'multiple' => true,
                                'size' => 4,
                                'id' => 'leftValues'
                            ));
                ?>
            </td>
            <td>&nbsp;</td>
            <td colspan="2" rowspan="8">
                <?php
                    echo $this->Form->input('phanquyen', array(
                                'options' => $arr_list_id_Nguoidung,
                                'label' => false,
                                'style' =>  'height: 300px; width: 100%; padding-left: 3px; padding-top: 3px; padding-bottom: 3px;',
                                'type' => 'select',
                                'multiple' => true,
                                'size' => 4,
                                'id' => 'rightValues'
                            ));
                ?>
            </td>
        </tr>
        <tr>
            <td>
                <div align="center">
                    <input id="btnRight" type="Button" value=">" style="width:50px">
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div align="center">
                    <input id="btnLeft" type="Button" value="<" style="width:50px">
                </div>
            </td>
        </tr>
        <tr>
            <td>&nbsp;</td>
        </tr>
        <tr>
          <td>
            <div align="center">
                <input type="submit" style="width:50px" value="Lưu" />
                <input type="hidden" name="hidden_nguoidung_nhom_id" value="<?php if(isset( $nguoidung_nhom_id )) echo $nguoidung_nhom_id;  ?>" />
            </div>
          </td>
        </tr>
        <tr>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td>&nbsp;</td>
        </tr>
    </table>
<?php } ?>
</div>
<?php echo $this->Form->end(); ?>
<script>
function load(inputString){
    $.ajax({
        url:"/admin/nguoidung_nhoms/loadnhom/" + inputString,
        beforeSend: function() {
            $('.ajaxLoading').html("<img src='/img/loading.gif' />");
        },
        success:function(html){
            $(".ajaxLoading").html(html);
        }
    });
}
$("#btnLeft").click(function () {
    var selectedItem = $("#rightValues option:selected");
    $("#leftValues").append(selectedItem);
});

$("#btnRight").click(function () {
    var selectedItem = $("#leftValues option:selected");
    $("#rightValues").append(selectedItem);
});
</script>